//
//  NewsView.m
//  SAT_NET
//
//  Created by lanou3g on 16/3/2.
//  Copyright © 2016年 郭丹. All rights reserved.
//

#import "NewsView.h"


@implementation NewsView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame sortArray:(NSMutableArray *)sortArray buttonWidth:(CGFloat )buttonWidth
{
    self = [super initWithFrame:frame];
    if (self) {
        //顶部分类
        CGRect frameSSV = CGRectMake(0, 0, kNewsSortW, kNewsSortH);
        self.sortSV = [[sortScrollV alloc] initWithSortArray:sortArray buttonWidth:buttonWidth frame:frameSSV];
        [self addSubview:self.sortSV];
        
        // 编辑分类按钮
        UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(kNewsSortW, 0, kScreenW - kNewsSortW, kNewsSortH)];
        rightView.backgroundColor = [UIColor colorWithRed: 45 / 255.0
                                                    green: 128 / 255.0
                                                     blue: 248 / 255.0
                                                    alpha:1];
        [self addSubview:rightView];
        
        self.rightButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        [self.rightButton setImage:[UIImage imageNamed:@"sort"] forState:(UIControlStateNormal)];
        [self.rightButton setTintColor:[UIColor whiteColor]];
        [self.rightButton setFrame:CGRectMake(10, 30, 24, 24)];
        
        [rightView addSubview:self.rightButton];
        
        // 下部展示
        self.showView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, kNewsSortH, kScreenW, kScreenH - kNewsSortH)];
        self.showView.contentSize = CGSizeMake(sortArray.count * kScreenW, 0);
        self.showView.backgroundColor = [UIColor whiteColor];
        self.showView.pagingEnabled = YES;
        self.showView.showsHorizontalScrollIndicator = NO;
        
        [self addSubview:self.showView];
        
        // 添加tableview
        for (int i = 0; i < sortArray.count; i ++) {
            UITableView *tableV = [[UITableView alloc] initWithFrame:CGRectMake(i * kScreenW, 0, kScreenW, kScreenH - kNewsSortH - 49) style:(UITableViewStylePlain)];
            tableV.tag = 200 + i;
            [self.showView addSubview:tableV];
            if ([self.ownPicArray containsObject:sortArray[i]] == YES) {
                UIScrollView *picSV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kScreenW , kPicH)];
                picSV.pagingEnabled = YES;
//
                picSV.showsHorizontalScrollIndicator = NO;
                NSInteger picNum = 0;
                if ([sortArray[i] isEqualToString:@"头条"]) {
                    picSV.contentSize = CGSizeMake(5 * kScreenW, 0);
                    picNum = 5;
                    
                } else {
                    picSV.contentSize = CGSizeMake(3 * kScreenW, 0);
                    picNum = 3;
                }
                for (int j = 0; j < picNum; j ++) {
                    // 图片
                    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(j * kScreenW, 0, kScreenW, kPicH)];
                    imageV.tag = i * 100 + 300 + j;
                    [picSV addSubview:imageV];
                    // 标题
                    UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(15, 210, 240, 30)];
                    titleLable.tag = i * 100 + 310 + j;
                    titleLable.textColor = [UIColor whiteColor];
                    [imageV addSubview:titleLable];
                    // 类型
                    UILabel *typeLable = [[UILabel alloc] initWithFrame:CGRectMake(280, 210, 20, 30)];
                    typeLable.tag = i * 100 + 320 + j;
                    [imageV addSubview:typeLable];
                    // 位置
                    UILabel *numberLable = [[UILabel alloc] initWithFrame:CGRectMake(320, 210, 40, 30)];
                    numberLable.tag = i * 100 + 330 + j;
                    numberLable.textColor = [UIColor whiteColor];
                    numberLable.font = [UIFont systemFontOfSize:12];
                    [imageV addSubview:numberLable];
                }
                tableV.tableHeaderView = picSV;
            }
        }
    }
    self.sortSV.tag = 101;
    self.showView.tag = 102;
    return self;
}


- (NSMutableArray *)ownPicArray {
    if (!_ownPicArray) {
        _ownPicArray = [NSMutableArray arrayWithObjects:@"头条",@"新闻",@"手机",@"电脑",@"攒机",@"平板",@"摄影", nil];
    }
    return _ownPicArray;
}

- (NSMutableArray *)noPicArray {
    if (!_noPicArray) {
        _noPicArray = [NSMutableArray array];
    }
    return _noPicArray;
}

@end
